home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: k-ohara@ux7.cso.uiuc.edu (Keith Edward O'hara)
- Newsgroups: comp.lang.c.moderated,comp.lang.c
- Subject: Re: HELP IN WRITING MY FIRST PROGRAM ASSINGMENT
- Date: 22 Feb 1996 06:31:40 -0600
- Organization: University of Illinois at Urbana Champaign CCSO
- Sender: clc@solutions.solon.com
- Approved: clc@solutions.solon.com
- Message-ID: <4ghnnc$dj9@solutions.solon.com>
- References: <3127FF7A.6442C3B8@eden.com> <4gfhkj$3p8@solutions.solon.com> <4ggbi9$83k@solutions.solon.com>
- NNTP-Posting-Host: solutions.solon.com
-
- Previously in comp.lang.c.moderated,
- >int
- >cmp(void *a, void *b) {
- > if (a < b) return -1;
- > if (a > b) return 1;
- > else return 0;
- >}
- was used as the callback function for qsort() (in an evil piece of code).
-
- Soon thereafter, mcv@pi.net (Miguel Carrasquer Vidal) wrote:
- > I tried it (using Borland C 4.5 large model), and it didn't work.
- ...
- >I wonder what my qsort() is doing wrong?
-
- So I had to try it. The qsort in Borland's library, and the one I wrote
- when I was learning C, both call the callback compare function with one
- address OUTSIDE the original array. In my qsort, I put the partitioning
- element in temporary storage (which I need anyway to do the swaps) and
- pass the address of the temporary storage as one argument to cmp().
-
- >[but the whole point was that, sorting an array by address is legal, but
- > does nothing. cmp was *intentionally* lying through its teeth, so
- > qsort would be a noop. swap(), as correctly pointed out, is never
- > called... It was in there because I was going to use my own quicksort,
- > before I realized the stdlib one would work. -mod]
-
- Two questions follow:
- Did Peter Seebach know all along that the pointers passed to cmp() would be
- not in the same array on some systems?
- [No. -mod]
- Does the standard (which I don't have to own since I'm not posting to
- comp.std.c) disallow this behavior of qsort()?
- [I hope so.]
-
- keith
- (who really shouln't be spending time on `evil' code,
- but just can't help it.)
-